import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
  {
    path: '/',
    redirect: '/home',
    component: () => import('../components/Home/Home.vue'),
  },
  {
    path: '/home',
    component: () => import('../components/Home/Home.vue'),
    redirect: '/index',
    children: [
      {
        path: '/index',
        component: () => import('../components/Index/Index.vue'),
        redirect: '/latestpurchase',
        children: [
          {
            path: '/latestpurchase',
            component: () => import('../components/Index/LatestPurchase.vue'),
          },
          {
            path: '/latestsupply/:ids',
            component: () => import('../components/Index/LatestSupply.vue'),
            props: true,
          }
        ]
      },
      { path: '/mine', component: () => import('../components/Mine/Mine.vue') },
      { path: '/classify', component: () => import('../components/Classify/Classify.vue') },
      { path: '/release', component: () => import('../components/Release/Release.vue') },
      { path: '/shippinglist', component: () => import('../components/ShippingList/ShippingList.vue') },
    ]
  },
  {
    path: '/information', component: () => import('../components/Information/Information.vue'), beforeEnter: (to, from, next) => {
      //判断是否已经登录
      if (!window.localStorage.token) {
        if (window.confirm('您还没有登录,请跳转到登录页?')) {
          next('/login');
        }
      }
      next();
    },
  },
  { path: '/latestpurchaselist', component: () => import('../components/Index/LatestPurchaseList.vue'), },
  {
    path: '/identity', component: () => import('../components/Change/Identity.vue'), beforeEnter: (to, from, next) => {
      //判断是否已经登录
      if (!window.localStorage.token) {
        if (window.confirm('您还没有登录,请跳转到登录页?')) {
          next('/login');
        }
      }
      next();
    },
  },
  {
    path: '/nickname', component: () => import('../components/Change/Nickname.vue'), beforeEnter: (to, from, next) => {
      //判断是否已经登录
      if (!window.localStorage.token) {
        if (window.confirm('您还没有登录,请跳转到登录页?')) {
          next('/login');
        }
      }
      next();
    },
  },
  {
    path: '/userphone', component: () => import('../components/Change/Userphone.vue'), beforeEnter: (to, from, next) => {
      //判断是否已经登录
      if (!window.localStorage.token) {
        if (window.confirm('您还没有登录,请跳转到登录页?')) {
          next('/login');
        }
      }
      next();
    },
  }, 
  { path: '/personalcertificate', component: () => import('../components/Certificate/PersonalCertificate.vue') },
  {path:'/address',component:()=>import('../components/Address/Address.vue')},
  {path:'/detail',component:()=>import('../components/Detail/Detail.vue')},
  {path:'/search/:ids',component:()=>import('../components/Search/Search.vue')},
  {path:'/purchase',component:()=>import('../components/Purchase/Purchase.vue')},
  {path:'/business',component:()=>import('../components/Business/Business.vue')},
  {path:'/guide',component:()=>import('../components/Guide/Guide.vue')},
  {path:'/registered',component:()=>import('../components/Registered/Registered.vue')},
    {
    path: "/releaseone",
    component: () => import("../components/Release/ReleaseOne.vue"),
  },
  {
    path: "/releasetwo",
    component: () => import("../components/Release/ReleaseTwo.vue"),
  },
  {path: '/login',component: () =>import ('../components/Login/Login.vue')},
  {path:'/information',component:()=>import('../components/Information/Information.vue')},
  {
    path:'/listheader',
    component:()=>import('../components/List/ListHeader.vue'),
    redirect:"/purchaselist",
    children:[
      {
        path:'/purchaselist',
        component:()=>import('../components/List/PurchaseList.vue')
      },
      {
        path:'/supplylist',
        component:()=>import('../components/List/SupplyList.vue'),
      },
    ]
  },
  {path:'/identity',component:()=>import('../components/Change/Identity.vue')},
  {path:'/nickname',component:()=>import('../components/Change/Nickname.vue')},
  {path:'/userphone',component:()=>import('../components/Change/Userphone.vue')},
  {path:'/:pathMatch(.*)*',component:()=>import('../components/NotFound/NotFound.vue')},
]


const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

export default router;